<!--  -->
<template>
  <!-- 所有的item 都展示同一个图片，同一个文字 -->
  <div class="tab-bar-item" @click="itemClick">
    <!-- 建议每一个插槽外面都包含一个div 防止属性设置出错 -->
    <div v-if="!isActive"><slot name="item-icon"></slot></div>
    <div v-else><slot name="item-icon-active"></slot></div>
    <!-- <div :class="{ active: isActive }"><slot name="item-text"></slot></div> -->
    <!-- 动态绑定style到 计算属性 -->
    <div :style="activeStyle"><slot name="item-text"></slot></div>
    <!-- 不能写死，使用插槽 -->
    <!-- <img src="../../assets/img/tabbar/fenlei.png" alt="" srcset="" />
    <div>首页</div> -->
  </div>
</template>

<script>

export default {
  name: "TarBarItem",
  data() {
    return {
      // isActive: true,
    };
  },
  computed: {
    isActive() {
      return this.$route.path.indexOf(this.path) !== -1;
    },
    activeStyle() {
      return this.isActive ? { color: this.activeColor } : {};
    },
  },
  props: {
    // 从父类传过来
    path: String,
    activeColor: {
      type: String,
      default: "red",
    },
  },
  methods: {
    itemClick() {
      // console.log('=======')
      this.$router.replace(this.path);
    },
  },
};
</script>
<style scoped>
.tab-bar-item {
  flex: 1;
  text-align: center;
  /* 一般是49px */
  height: 49px;
  font-size: 14px;
}
.tab-bar-item img {
  width: 24px;
  height: 24px;
  margin-top: 3px;
  vertical-align: middle;
}
.active {
  color: red;
}
</style>